<?php
namespace app\admin\widget;
use think\Db;

class WechatWidget{
    public function fansnum($user_id=''){
        $num = Db::name('wx_fans')->where('user_id',$user_id)->count();
        return $num;
    }
    public function account($user_id=''){
        $data = Db::name('user')->where('id',$user_id)->find();
        return $data['user_login'];
    }
    public function payCate($id =''){
        $user_id =cmf_get_current_admin_id();
        $cate = Db::name('pay_cate')->where('user_id',$user_id)->select();
        $op = '';
        if(!empty($cate)){
            foreach ($cate as $k=>$v){
                if($id == $v['id']){
                    $op .= '<option selected value="'.$v['id'].'">'.$v['name'].'</option>';
                }else{
                    $op .= '<option value="'.$v['id'].'">'.$v['name'].'</option>';
                }
            }
        }
        echo $op;
    }
    public function payFans($openid=''){
        $user_id =cmf_get_current_admin_id();
        $cate = Db::name('wx_fans')->where('user_id',$user_id)->select();
        $op = '';
        if(!empty($cate)){
            foreach ($cate as $k=>$v){
                if(!empty($v['louhao'])||!empty($v['danyuanhao'])||!empty($v['louceng'])||!empty($v['fangjianhao'])){
                    if($openid == $v['openid']){
                        if(!empty($v['remark'])){
                            $op .= '<option selected value="'.$v['openid'].'">'.$v['remark'].'&nbsp;&nbsp;&nbsp;&nbsp;'.$v['louhao'].'号楼'.$v['danyuanhao'].'单元'.$v['louceng'].'层'.$v['fangjianhao'].'</option>';
                        }else{
                            $op .= '<option selected value="'.$v['openid'].'">'.$v['nickname'].'&nbsp;&nbsp;&nbsp;&nbsp;'.$v['louhao'].'号楼'.$v['danyuanhao'].'单元'.$v['louceng'].'层'.$v['fangjianhao'].'</option>';
                        }
                    }else{
                        if(!empty($v['remark'])){
                            $op .= '<option value="'.$v['openid'].'">'.$v['remark'].'&nbsp;&nbsp;&nbsp;&nbsp;'.$v['louhao'].'号楼'.$v['danyuanhao'].'单元'.$v['louceng'].'层'.$v['fangjianhao'].'</option>';
                        }else{
                            $op .= '<option value="'.$v['openid'].'">'.$v['nickname'].'&nbsp;&nbsp;&nbsp;&nbsp;'.$v['louhao'].'号楼'.$v['danyuanhao'].'单元'.$v['louceng'].'层'.$v['fangjianhao'].'</option>';
                        }
                    }
                }
            }
        }
        echo $op;
    }
    
}